<template>
  <div>
    <van-nav-bar title="测试页面" left-text="返回" left-arrow @click-left="$router.push('/home')" />

    <div>
      <h3>VUEX测试数据</h3>
      <div>购物车数量：{{cartCount}}</div>

      <section class="goods_lists" v-for="item in cartGoods">
        <div class="goods_info">
          <div>id: {{ item.id }}</div>
          <div>价格: {{ item.price }}</div>
          <div>数量: {{ item.quantity }}</div>
        </div>

        <div style="text-align: right;">
          <button @click="add(item.id)">加法</button>
          <button @click="reduc(item.id)">减法</button>
        </div>
      </section>
    </div>
  </div>
</template>

<script>
  import {mapState,mapGetters,mapActions} from 'vuex'
export default {
  data() {
    return {
      sex: 1,
      sex2: this.$store.getters.getSex,
    };
  },
  computed: {
    ...mapState({
      cartGoods:state=>state.cartGoods,
      cartCounter:state=>state.cartCounter,
      sex_val:state=>state.sex
    }),


  },
  created() {
    console.log(this.sex_val);
  },
  methods: {
    add(id) {
      this.$store.commit('inc', id);
    },
    reduc(id) {
      this.$store.commit('dec', id);
    }
  }
};
</script>

<style lang="scss" scoped="scoped">
.goods_lists {
  margin: 20px 0;
  background-color: white;
}
.goods_info {
  display: flex;
  padding: 10px 0;
  div {
    flex: 1;
    text-align: center;
  }
}
</style>
